635A - Orchestra - CodeForces Solution


brute force implementation *1100

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <cmath>
#include <stack> 
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
using namespace std;
int arr[11][11];

int sum(int i,int j ,int a,int b){
	int ss=0;
	for(int k=i;k<i+a;k++ ){
		for(int u=j;u<j+b;u++)ss+=arr[k][u];
	}
	return ss;
}
int main(){
int n,m;
cin>>n>>m;
int nn,k;
cin>>nn>>k;
for(int i=0;i<nn;i++){
int x,y;
cin>>x>>y;
	arr[x-1][y-1]=1;
}
int ans[n][m];
for(int i=0;i<n;i++){
	for(int j=0;j<m;j++){
		if(i==0&&j==0)ans[i][j]=arr[i][j];
		else if(i==0)ans[i][j]=arr[i][j]+ans[i][j-1];
		else if(j==0)ans[i][j]=arr[i][j]+ans[i-1][j];
		else{
			ans[i][j]=arr[i][j]+ans[i][j-1]+ans[i-1][j]-ans[i-1][j-1];
		}
	}
}

///////////////////////////
int sum=0;
for(int a=0;a<n;a++){
	for(int b=0;b<m;b++){
		for(int i=0;i<n-a;i++){
			for(int j=0;j<m-b;j++){
				int x;
			if(i==0&&j==0)x=ans[i+a][j+b];
			else if(i==0)x=ans[i+a][j+b]-ans[i+a][j-1];
			else if(j==0)x=ans[i+a][j+b]-ans[i-1][j+b];
			else x=x=ans[i+a][j+b]-ans[i-1][j+b]-ans[i+a][j-1]+ans[i-1][j-1];
			if(x>=k)sum++;
		//	cout<<a<<" "<<b<<" "<<x<<"\n";
			}
		}
	}
}cout<<sum<<"\n";
	return 0;
}


Comments

Submit
0 Comments
More Questions

1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament
1047B - Cover Points
1381B - Unmerge
1256A - Payment Without Change
908B - New Year and Buggy Bot
979A - Pizza Pizza Pizza
731A - Night at the Museum